import { inject, observer } from 'mobx-react';
import { Button, Modal } from 'antd';
import {WeaErrorPage, WeaTools, WeaTop, WeaInput, WeaDialog, WeaRightMenu, WeaFormItem, WeaLocaleProvider} from 'ecCom';
const getLabel = WeaLocaleProvider.getLabel;
class EchartSaveAs extends React.Component {
    constructor(props) {
        super(props);
        this.onSetState = this.onSetState.bind(this);
        this.getButtons = this.getButtons.bind(this);
        this.getRightMenu = this.getRightMenu.bind(this);
        this.onRightMenuClick = this.onRightMenuClick.bind(this);
        this.onSubmit = this.onSubmit.bind(this);
        this.state = {
            visible: false,
            title: '',
        }
    }
    onSetState(state){
        this.setState(state);
    }
    onSubmit(){
        const { onSave } = this.props;
        const { title } = this.state;
        if(!title.trim()){
            Modal.error({
                title: getLabel(15172,'系统提示'),
                content: getLabel(127697,"模板名称不能为空！"),
            });
            return;
        }
        onSave({type:'saveas', title});
        this.setState({visible: false});
    }
    getButtons(){
        let btns = [];
        btns.push(<Button ecId={`${this && this.props && this.props.ecId || ''}_Button@23ws60`} type="primary" onClick={this.onSubmit}>{getLabel(826,'确定')}</Button>);
        btns.push(<Button ecId={`${this && this.props && this.props.ecId || ''}_Button@w07ih7`} onClick={this.onSetState.bind(this,{visible:false})}>{getLabel(31129,'取消')}</Button>)
        return btns
    }
    getRightMenu(){
        let btns = [];
        btns.push({
            icon: <i className='icon-coms-Preservation'/>,
            content:getLabel(30986, '保存')
        });
        btns.push({
            icon: <i className='icon-coms-go-back'/>,
            content:getLabel(31129,'取消')
        });
        return btns
    }
    onRightMenuClick(key){
        switch(key){
            case '0':
                this.onSubmit();
                break;
            case '1':
                this.setState({visible:false});
                break;
        }
    }
    render() {
        const { title, visible } = this.state;
        return <WeaDialog ecId={`${this && this.props && this.props.ecId || ''}_WeaDialog@y7czc4`} 
                    title={getLabel(350, '另存为')}
                    visible={visible} 
                    closable={true}
                    onCancel={this.onSetState.bind(this,{visible: false})}
                    icon='icon-coms-portal'
                    iconBgcolor='#1a57a0'
                    maskClosable={false}
                    buttons={this.getButtons()}
                    style={{width: 520, height: 237}}
                  >
                  <WeaRightMenu ecId={`${this && this.props && this.props.ecId || ''}_WeaRightMenu@qlxfox`} datas={this.getRightMenu()} onClick={this.onRightMenuClick}>
                    <div className="portal-esetting-echart-saveas-title">
                      <WeaFormItem ecId={`${this && this.props && this.props.ecId || ''}_WeaFormItem@06r2x9`}
                          label={getLabel(28050,"模板名称")}
                          labelCol={{span: 6}}
                          wrapperCol={{span: 18}}>
                            <WeaInput ecId={`${this && this.props && this.props.ecId || ''}_WeaInput@loi4lz`} viewAttr={3} style={{width: 280}} fieldName="title" value={title} onChange={value=>this.setState({title: value})}/>
                      </WeaFormItem>
                    </div>
                </WeaRightMenu>
        </WeaDialog>
    }
}
class MyErrorHandler extends React.Component {
    render() {
        const hasErrorMsg = this.props.error && this.props.error !== "";
            return ( <WeaErrorPage ecId={`${this && this.props && this.props.ecId || ''}_WeaErrorPage@txr188`} msg = { hasErrorMsg ? this.props.error : getLabel(385218,"对不起，该页面异常，请联系管理员！") }/>
        );
    }
}
EchartSaveAs = WeaTools.tryCatch(React, MyErrorHandler, { error: "" })(EchartSaveAs);
export default EchartSaveAs;